package com.tianyi.controller.classify;

import com.tianyi.classify.ClassifyService;
import com.tianyi.controller.BaseController;
import com.tianyi.lib.model.WebResult;
import com.tianyi.lib.req.BrandReq;
import com.tianyi.lib.req.ClassifyReq;
import com.tianyi.lib.req.ClassifyReq;
import com.tianyi.model.SimpleLoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 分类controller
 *
 * @author cuixuhui
 * @date 2020/06/04
 */
@RestController
@RequestMapping("classify")
public class ClassifyController extends BaseController {

    @Autowired
    private ClassifyService classifyService;

    @RequestMapping(value = "addClassify", method = RequestMethod.POST)
    public WebResult<?> addClassify(@RequestBody ClassifyReq req){

        SimpleLoginUser user = getUserFromRequest();
        if (Objects.isNull(user)){
            return WebResult.error("user is null");
        }
        handLoginUser(req);
        return classifyService.addClassify(req);
    }

    @RequestMapping(value = "deleteClassifyById", method = RequestMethod.GET)
    public WebResult<?> deleteClassifyById(ClassifyReq req){

        SimpleLoginUser user = getUserFromRequest();
        if (Objects.isNull(user)){
            return WebResult.error("user is null");
        }
        handLoginUser(req);
        return classifyService.deleteClassifyById(req);
    }

    @RequestMapping(value = "updateClassify", method = RequestMethod.POST)
    public WebResult<?> updateClassify(@RequestBody ClassifyReq req){

        SimpleLoginUser user = getUserFromRequest();
        if (Objects.isNull(user)){
            return WebResult.error("user is null");
        }
        handLoginUser(req);
        return classifyService.updateClassify(req);
    }

    @RequestMapping(value = "queryClassifyPage", method = RequestMethod.GET)
    public WebResult<?> queryClassifyPage(ClassifyReq req){

        SimpleLoginUser user = getUserFromRequest();
        if (Objects.isNull(user)){
            return WebResult.error("user is null");
        }
        handLoginUser(req);
        return classifyService.queryClassifyPage(req);
    }

    @RequestMapping(value = "getClassifyPullDown", method = RequestMethod.GET)
    public WebResult<?> getClassifyPullDown(ClassifyReq req){

        SimpleLoginUser user = getUserFromRequest();
        if (Objects.isNull(user)){
            return WebResult.error("user is null");
        }
        handLoginUser(req);
        return classifyService.getClassifyPullDown(req);
    }
}
